package data;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

import settings.Settings;



public class Names 
{
	public static ArrayList<String> firstNames = new ArrayList<String>();
	public static ArrayList<String> lastNames = new ArrayList<String>();
	
	public static int index = 0;
	
	public static boolean initialized;
	
	public Names()
	{
		Names.loadNames();
	}
	
	private static void loadNames()
	{
		try 
		{
			BufferedReader stream = new BufferedReader(new FileReader(Settings.dataPath+"firstname.dat"));
			String line;
			while ((line = stream.readLine()) != null)   
			{
				line = line.replaceAll("\t", "");
				line = line.replaceAll(" ", "");
				firstNames.add(line);
			}
			stream.close();
			
			stream = new BufferedReader(new FileReader(Settings.dataPath+"lastname.dat"));
			while ((line = stream.readLine()) != null)   
			{
				line = line.replaceAll("\t", "");
				line = line.replaceAll(" ", "");
				lastNames.add(line);
			}
			
			stream.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}		
	}
	
	public static String getName()
	{
		if(!Names.initialized)
		{
			Names.loadNames();
			Names.initialized = true;
		}
		return firstNames.get(index % firstNames.size()) + " " + lastNames.get(index++ % lastNames.size());
	}
}
